home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_exmh.idb / usr / freeware / lib / exmh-2.5 / seditSel.tcl.z / seditSel.tcl
Text File  |  2002-07-08  |  6KB  |  205 lines

  1. proc SeditCiteSelectionPar { draft t } {
  2.     global sedit address
  3.     if [catch {selection get} txt] {
  4.         SeditMsg $t "No selection"
  5.         return
  6.     }
  7.     $t insert insert "\n$address wrote:\n"
  8.     regsub -all "(\n|^)" $txt "\\1$sedit(pref,replPrefix)" txt
  9.     set res [exec par -rTbgqR -B=.\?_A_a -Q=_s\>\| $sedit(lineLength) << $txt]
  10.     $t insert insert "$res\n"
  11. }
  12.  
  13. proc SeditCiteSelectionNoFmt { draft t } {
  14.     global sedit address
  15.     if [catch {selection get} txt] {
  16.         SeditMsg $t "No selection"
  17.         return
  18.     }
  19.     $t insert insert "\n$address wrote:\n"
  20.     regsub -all "(\n|^)" $txt "\\1$sedit(pref,replPrefix)" txt
  21.     $t insert insert "$txt\n"
  22. }
  23.  
  24. proc Sedit_FormatParagraphPar { t } {
  25.     global sedit address
  26.     if [catch {$t index "sel.first linestart"} first] {
  27.     set first [$t index "insert linestart"]
  28.     set last [$t index "insert lineend"]
  29.     while 1 {
  30.         set line [$t get $first "$first lineend"]
  31.         set len [string length $line]
  32.         if {$len == 0} {
  33.         break
  34.         }
  35.         set first [$t index "$first - 1line"]
  36.         if {[regexp ^-- $line] || [$t compare $first <= hlimit]} {
  37.         break
  38.         }
  39.     }
  40.     set first [$t index "$first + 1line"]
  41.     while 1 {
  42.         set line [$t get "$last linestart" $last]
  43.         set len [string length $line]
  44.         if {($len == 0) || [regexp ^-- $line]} {
  45.         set last [$t index "$last - 1line lineend +1char"]
  46.         break
  47.         }
  48.         set nlast [$t index "$last + 1line lineend"]
  49.         if {[$t compare $nlast == $last]} {
  50.         break
  51.         }
  52.         set last $nlast
  53.     }
  54.     } else {
  55.     set last [$t index "sel.last lineend"]
  56.     }
  57.     set line [$t get $first "$last -1char"]
  58.     set tags [$t tag names $first]
  59.     SeditMsg $t "Reformatting paragraph..."
  60.     if [catch {set fmtline [exec par -rTbgqR -B=.\?_A_a -Q=_s\>\| $sedit(lineLength) << [set line]]}] {
  61.       SeditMsg $t "par error"
  62.     } else {
  63.       $t delete $first $last
  64.       $t mark set insert $first
  65.       if {[string compare "" $fmtline] != 0} {
  66.         $t insert insert "$fmtline\n"
  67.       }
  68.       SeditMsg $t ""
  69.     }
  70.     $t mark set insert "insert -1char"
  71. }
  72. proc SeditSelFmt {t} {
  73.     global sedit
  74.  
  75.     if [catch {selection get} txt] {
  76.     SeditMsg $t "No selection"
  77.     return
  78.     }
  79.  
  80.     set res [exec par -rTbgqR -B=.\?_A_a -Q=_s\>\| $sedit(lineLength) << $txt]
  81.     if ![catch {$t index sel.first} tndx] {
  82.         $t delete sel.first sel.last
  83.     } else {
  84.     set tndx [$t index insert]
  85.     }
  86.     $t mark set insert $tndx
  87.     $t insert insert "$res\n"
  88. }
  89.  
  90.  
  91. proc SeditSelFmtArg {t} {
  92.     global par sedit
  93.     set par(t) $t
  94.  
  95.     if [catch {selection get} par(txt)] {
  96.     SeditMsg $t "No selection"
  97.     return
  98.     }
  99.     if [Exwin_Toplevel .par "Format" Format] {
  100.     set par(options) "rTbgqR"
  101.     set par(body) ".?_A_a"
  102.     set par(quote) "_s>|"
  103.     set par(protect) ""
  104.     set par(width) $sedit(lineLength)
  105.     .par.but.quit configure -command {Exwin_Dismiss .par nosize}
  106.     Widget_BeginEntries 7 17
  107.     Widget_LabeledEntry .par.options "Options:" par(options)
  108.     Widget_LabeledEntry .par.body "Body:" par(body)
  109.     Widget_LabeledEntry .par.quote "Quote:" par(quote)
  110.     Widget_LabeledEntry .par.protect "Protect:" par(protect)
  111.     Widget_LabeledEntry .par.width "Width:" par(width)
  112.     Widget_AddBut .par.but format "Format" {
  113.         Exmh_Status "Formatting Selection"
  114.         if [catch {exec par -$par(options) -B=$par(body) -Q=$par(quote) -P=$par(protect) $par(width) << $par(txt)} res] {
  115.             Exmh_Status "Error: Invalid options for Par" red
  116.         } else {
  117.                 if ![catch {$par(t) index sel.first} tndx] {
  118.                     $par(t) delete sel.first sel.last
  119.                } else {
  120.                     set tndx [$par(t) index insert]
  121.                 }
  122.                 $par(t) mark set insert $tndx
  123.                 $par(t) insert insert "$res\n"
  124.             Exmh_Status ""
  125.             Exwin_Dismiss .par nosize
  126.         }
  127.     }
  128.     }
  129. }
  130.  
  131.  
  132. proc SeditSelSpell { f t } {
  133.     global sedit editor wish
  134.  
  135.     set parent [file root $f]
  136.     catch {[destroy $parent.spell]}
  137.  
  138.     if [catch {selection get} txt] {
  139.     SeditMsg $t "No selection"
  140.     return
  141.     }
  142.  
  143.     set path [Env_Tmp]/exmh.s[pid].[file tail $t]
  144.     set out [open $path w 0600]
  145.     puts $out $txt
  146.     close $out
  147.  
  148.     switch -- $sedit(spell) {
  149.     ispell {set prog {exmh-async xterm -e ispell}}
  150.     custom {set prog $editor(spell)}
  151.     default {set prog spell}
  152.     }
  153.     if [string match exmh-async* $prog] {
  154.     # exmh-async isn't really right
  155.     # craft a wish script instead
  156.     set script [Env_Tmp]/exmh.w[pid].[file tail $t]
  157.     if [catch {open $script w 0600} out] {
  158.         Exmh_Status $out
  159.         return 0
  160.     }
  161.     puts $out "wm withdraw ."
  162.     puts $out "catch \{"
  163.     puts $out "exec [lrange $editor(spell) 1 end] $path"
  164.     puts $out "\}"
  165.     puts $out [list send [winfo name .] [list SeditReplaceSel $t $path]]
  166.     puts $out "exec rm -f $path"
  167.     puts $out "exec rm -f $script"
  168.     puts $out exit
  169.     close $out
  170.     exec $wish -f $script &
  171.     return
  172.     }
  173.  
  174.     # Display the results of the spell program
  175.     catch {eval exec $prog {$path}} result
  176.     catch {exec rm $path}
  177.  
  178.     set f2 [Widget_Frame $parent spell {top fill}]
  179.  
  180.     set lines [llength [split $result \n]]
  181.     set height [expr {$lines > 8 ? 8 : $lines}]
  182.     set t2 [Widget_Text $f2 $height]
  183.     $t2 configure -height $height    ;# Widget_Text broken
  184.     $t2 insert 1.0 $result
  185.     $t2 config -state disabled
  186.     pack $f2 -before $f -side top
  187. }
  188.  
  189. proc SeditReplaceSel { t infile } {
  190.     set in [open $infile]
  191.  
  192.     if ![catch {$t index sel.first} tndx] {
  193.         $t delete sel.first sel.last
  194.     } else {
  195.     set tndx [$t index insert]
  196.     }
  197.  
  198.     $t mark set insert $tndx
  199.     $t insert insert [read -nonewline $in] 
  200.  
  201.     close $in
  202. }
  203.  
  204.  
  205.